<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>vue-router默认显示子路由 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="有种简单的解决方案，使用自带的重定向功能 重定向修改router的js文件，在需要设置默认子路由的配置中加入redirect属性，并指定重定向的路径为默认子路由的路径即可 该方法直接改变url 123456789101112131415161718&amp;#123;    path: &#39;&#x2F;pc&#39;,    name: &#39;PersonalCenter&#39;,    co">
<meta property="og:type" content="article">
<meta property="og:title" content="vue-router默认显示子路由">
<meta property="og:url" content="http://yoursite.com/2020/08/03/vue-router%E9%BB%98%E8%AE%A4%E6%98%BE%E7%A4%BA%E5%AD%90%E8%B7%AF%E7%94%B1/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="有种简单的解决方案，使用自带的重定向功能 重定向修改router的js文件，在需要设置默认子路由的配置中加入redirect属性，并指定重定向的路径为默认子路由的路径即可 该方法直接改变url 123456789101112131415161718&amp;#123;    path: &#39;&#x2F;pc&#39;,    name: &#39;PersonalCenter&#39;,    co">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-08-03T01:42:38.000Z">
<meta property="article:modified_time" content="2020-08-03T05:41:48.298Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 4.2.1"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-vue-router默认显示子路由" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/08/03/vue-router%E9%BB%98%E8%AE%A4%E6%98%BE%E7%A4%BA%E5%AD%90%E8%B7%AF%E7%94%B1/" class="article-date">
  <time datetime="2020-08-03T01:42:38.000Z" itemprop="datePublished">2020-08-03</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      vue-router默认显示子路由
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>有种简单的解决方案，使用自带的重定向功能</p>
<h2 id="重定向"><a href="#重定向" class="headerlink" title="重定向"></a>重定向</h2><p>修改router的js文件，在需要设置默认子路由的配置中加入redirect属性，并指定重定向的路径为默认子路由的路径即可</p>
<p>该方法直接改变url</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    path: &#39;&#x2F;pc&#39;,</span><br><span class="line">    name: &#39;PersonalCenter&#39;,</span><br><span class="line">    component: () &#x3D;&gt; import(&#39;..&#x2F;views&#x2F;PersonalCenter.vue&#39;),</span><br><span class="line">    redirect: &#39;&#x2F;pc&#x2F;pccomp&#39;,</span><br><span class="line">    children: [</span><br><span class="line">    &#123;</span><br><span class="line">        path: &#39;pccomp&#39;,</span><br><span class="line">        name: &#39;personalCenterComp&#39;,</span><br><span class="line">        component: () &#x3D;&gt; import(&#39;..&#x2F;views&#x2F;components&#x2F;personalCenterComp.vue&#39;)</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">        path: &#39;mscomp&#39;,</span><br><span class="line">        name: &#39;mySearchComp&#39;,</span><br><span class="line">        component: () &#x3D;&gt; import(&#39;..&#x2F;views&#x2F;components&#x2F;mySearchComp.vue&#39;)</span><br><span class="line">    &#125;,</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<hr>
<h2 id="其他方案"><a href="#其他方案" class="headerlink" title="其他方案"></a>其他方案</h2><p>曾尝试使用别名功能，过程中发现给父路由设置别名后，原本指向的路径要指定为所需默认子路由的路径，但这样一来，父路由路径改变，子路由路径也会跟着改变，故在嵌套路由中不能使用别名功能来解决该问题。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/03/vue-router%E9%BB%98%E8%AE%A4%E6%98%BE%E7%A4%BA%E5%AD%90%E8%B7%AF%E7%94%B1/" data-id="ckde35gni0000zovped9bfh4v" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2020/09/04/table%E4%B8%AD%E6%BA%A2%E5%87%BA%E6%96%87%E6%9C%AC%E6%98%BE%E7%A4%BA'...'/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          table中溢出文本显示&#39;...&#39;
        
      </div>
    </a>
  
  
    <a href="/2020/07/20/Markdown%E5%B8%B8%E7%94%A8%E8%AF%AD%E6%B3%95%E7%AE%80%E4%BB%8B/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Markdown常用语法简介</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/09/">September 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/08/">August 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/07/">July 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2020/09/07/js%E9%87%8CforEach%E9%81%8D%E5%8E%86%E4%B8%AD%E4%BD%BF%E7%94%A8continue%E6%8A%A5%E9%94%99/">js里forEach遍历中使用continue报错</a>
          </li>
        
          <li>
            <a href="/2020/09/04/table%E4%B8%AD%E6%BA%A2%E5%87%BA%E6%96%87%E6%9C%AC%E6%98%BE%E7%A4%BA'...'/">table中溢出文本显示&#39;...&#39;</a>
          </li>
        
          <li>
            <a href="/2020/08/03/vue-router%E9%BB%98%E8%AE%A4%E6%98%BE%E7%A4%BA%E5%AD%90%E8%B7%AF%E7%94%B1/">vue-router默认显示子路由</a>
          </li>
        
          <li>
            <a href="/2020/07/20/Markdown%E5%B8%B8%E7%94%A8%E8%AF%AD%E6%B3%95%E7%AE%80%E4%BB%8B/">Markdown常用语法简介</a>
          </li>
        
          <li>
            <a href="/2020/07/18/hello-world/">Hello World</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>